< previous page page_536 next page >

Page 536
Listing 14.3. continued
    GoTo LocalExit ' all done
    '
LocalErr:
    strMsg = CStr(Err.Number) & " - " & Err.Description
    MsgBox strMsg, vbCritical, "CreateErr"
    '
    Open "junk.txt" For Input As 1 ' create another error
    Resume Next
    '
LocalExit:
    '
End Sub
Notice that this routine is quite similar to the code from Listing 14.2. The biggest difference is in the lines of code in the error-handling portion of the subroutine. Notice that Visual Basic attempts to open a text file for input. Since this file does not currently exist, this action causes an error.
Now add the code from Listing 14.4 to the cmdCascadeErr_Click event. This is the code that calls the CreateErr routine.
Type.gifListing 14.4. Coding the cmdCascadeErr routine.
Private Sub cmdCascadeErr_Click()
    '
    ' create an error cascade
    '
    On Error GoTo LocalErr
    '
    Dim strMsg As String
    '
    CreateErr ' call another routine
    GoTo LocalExit ' all done
    '
LocalErr:
    strMsg = CStr(Err.Number) & " - " & Err.Description
    MsgBox strMsg, vbCritical, "cmdCascadeErr"
    Resume Next
    '
LocalExit:
    '
End Sub
Save the program and run it to see the results. When you first click the command button, you see the error message that announces the overflow error. Notice that the title of the message box indicates that the error is being reported by the CreateErr routine (see Figure 14.2).

 
< previous page page_536 next page >

If you like this book, buy it!